package com.zl.learning.arithmetic.rbtree;

import org.junit.Test;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.IntStream;

public class Test1 {
    public static void main(String[] args) {
        TreeMap<Integer, Integer> map = new TreeMap<>();
        map.put(1, 1);
        map.put(2, 2);
        map.put(3, 3);
        map.put(4, 4);
        map.put(5, 5);
        map.put(6, 6);
        map.put(7, 7);
        map.put(8, 8);
        map.put(9, 9);
        HashMap<Integer, Integer> map2 = new HashMap<>();
        map2.put(1, 1);
        map2.put(2, 2);
        map2.put(3, 3);
        map2.put(4, 4);
        map2.put(5, 5);
        map2.put(6, 6);
        map2.put(7, 7);
        map2.put(8, 8);
        map2.put(9, 9);
    }

    private void preOrder(RBTree node) {
        RBTree.Node root = node.getRoot();
        Deque<RBTree.Node> stack = new LinkedList<>();
        while (root != null || !stack.isEmpty()) {
            while (root != null) {
                System.out.print(root.getData() + " ");
                stack.push(root);
                root = root.getLeft();
            }
            if (!stack.isEmpty()) {
                root = stack.pop();
                root = root.getRight();
            }
        }
    }

    @Test
    public void test1() {
        RBTree rbTree = new RBTree();
        IntStream.rangeClosed(1, 12).forEach(rbTree::add);
        System.out.println(rbTree);
        rbTree.preOrderTraverse();
        System.out.println();
        rbTree.inOrderTraverse();
        System.out.println();
        rbTree.postOrderTraverse();
        System.out.println();
        preOrder(rbTree);
    }

    @Test
    public void test2() {
        Path p = Paths.get("D:\\data\\data\\李四");
        Path p2 = p.resolve("李四");
        System.out.println(p2);
    }

    @Test
    public void test3() {
        LocalDateTime dateTime = LocalDateTime.now().withDayOfYear(1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        System.out.println(dateTime.format(formatter));
    }

    @Test
    public void test4() {
        Integer a = getInt();
        System.out.println(a);
    }

    private Integer getInt() {
        return null;
    }

    @Test
    public void test5() {
        String fileName = "data (3).jpg";
        String[] types = fileName.split("\\.");
        System.out.println(Arrays.toString(types));
    }

    @Test
    public void test6() {
        int a = 1;
        a = a << 30;
        System.out.println(a);
    }
}
